package com.education.seckill.mq;

import com.education.seckill.entity.SeckillGood;
import com.education.seckill.service.ISeckillGoodService;
import com.education.seckill.service.ISeckillOrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class mqReceiver {

    @Autowired
    private ISeckillOrderService iSeckillOrderService;

    @Autowired
    private ISeckillGoodService seckillGoodService;


    @RabbitListener(queues = "seckill_queue")
    public void receiver(Long id){
        SeckillGood good = seckillGoodService.getById(id);
        if(good.getSGoodStock() <= 0){
            return;
        }
        //接收到消息 ，下单
        int order = iSeckillOrderService.createOrder(id);
        return;
    }

}
